package com.chaodev.base.service.impl;

import com.chaodev.base.dao.SouthNetWorkDao;
import com.chaodev.base.model.SNDataVO;
import com.chaodev.base.service.SouthNetWorkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * vcbase
 *
 * @author 95634
 * @描述
 * @date 2023/3/6 10:44
 **/
@Service
public class SouthNetWorkServiceImpl implements SouthNetWorkService {

    @Autowired
    SouthNetWorkDao dao;

    @Override
//    @SpecifyDataSource(DataSourceTypeEnum.ORACLE_DB)
    public List<Map<String, Object>> getCityCount() {
        return dao.getCityCount();
    }

    @Override
//    @SpecifyDataSource(DataSourceTypeEnum.ORACLE_DB)
    public List<SNDataVO> getCityDetail(String qx,String code,String flag) {
        List<SNDataVO> cityDetail = dao.getCityDetail(qx,code,flag);
        return cityDetail;
    }

    @Override
//    @SpecifyDataSource(DataSourceTypeEnum.ORACLE_DB)
    public List<Map<String, Object>> getTDSC(String qx) {
        return dao.getTDSC(qx);
    }

    @Override
//    @SpecifyDataSource(DataSourceTypeEnum.ORACLE_DB)
    public List<Map<String, Object>> getTDQJCount(String qx) {
        return dao.getTDQJCount(qx);
    }

    @Override
    public List<Map<String, Object>> getCameraNum() {
        return dao.getCameraNum();
    }

    @Override
    public List<Map<String, Object>> getCameraDetil() {
        return dao.getCameraDetil();
    }

    @Override
//    @SpecifyDataSource(DataSourceTypeEnum.ORACLE_DB)
    public List<Map<String, Object>> getHisTDData(String qx) {
        return dao.getHisTDData(qx);
    }

    @Override
//    @SpecifyDataSource(DataSourceTypeEnum.ORACLE_DB)
    public List<Map<String, Object>> getPQTDData() {
        List<Map<String, Object>> pqtdData = dao.getPQTDData();
        int allNum=0;
        allNum=pqtdData.stream().mapToInt(d->Integer.valueOf(d.get("num").toString())).sum();
        float v= 0.00F;
        String lastValue=null;
        DecimalFormat decimalFormat=new DecimalFormat("0.0%");
        List<Map<String, Object>> retrunData=new ArrayList<>();
        for (Map<String, Object> pqtdDatum : pqtdData) {
            if(allNum>0) {
                v = Integer.valueOf(pqtdDatum.get("num").toString()) / Float.valueOf(allNum);
            }
            lastValue=decimalFormat.format(v);
            pqtdDatum.put("zb",lastValue);
            retrunData.add(pqtdDatum);
        }
        return retrunData;
    }
}
